// DatabaseElement.h: interface for the DatabaseElement class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_DATABASEELEMENT_H__6335ABE4_5316_4254_9325_AA076DF6C4C9__INCLUDED_)
#define AFX_DATABASEELEMENT_H__6335ABE4_5316_4254_9325_AA076DF6C4C9__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "UERecordset.h"
#include "newRegister.h"

namespace PDMS
{
	namespace PDMSDBIF
	{
		class DatabaseElement;
		typedef AllocateRegObject< StdString, DatabaseElement > DatabaseElementBase;
		typedef DatabaseElementBase::Register_ DatabaseElementRegister;

		class DatabaseBase;
		class DllExport DatabaseElement : public DatabaseElementBase 
		{
			friend class DatabaseBase;
			DECLARE_DYNAMIC_EX( DatabaseElement );
		public:
			DatabaseElement();
			virtual ~DatabaseElement();
			
		public:
			UESoft::ErrorStatus Open( const StdString& strSQLCondition = StdString() );
			virtual void MoveFirst();
			virtual void MoveNext();
			virtual void MoveLast();
			virtual BOOL IsEnd();
			virtual BOOL IsNull();

			virtual UESoft::ErrorStatus Close() {
				m_bIsOpen = FALSE;
				return UESoft::eOk;
			}
			virtual UESoft::ErrorStatus Update() = 0;

		protected:
			virtual StdString GetOpenSQL( const StdString& strCondition ) = 0;

			DatabaseBase* GetDatabase() const {
				return m_pDatabase;
			}

			UERecordsetPtr& Recordset() {
				return m_ResPtr;
			}
			
		
		private:
			void SetDatabase( DatabaseBase* pDatabase ) {
				ASSERT( pDatabase );
				m_pDatabase = pDatabase;
			}

		private:
			DatabaseBase* m_pDatabase;
			BOOL m_bIsOpen;

		protected:
			UERecordsetPtr m_ResPtr;
		};
				
		class DllExport DatabaseElementFactory : public DatabaseElement
		{
			DECLARE_DYNAMIC_EX( DatabaseElementFactory );
			DECLARE_REGISTER( Design_VersionOne );
		public:
			DatabaseElementFactory(){}
			virtual ~DatabaseElementFactory(){}
		};
#define ALLRECORD _T("All")
	}
}

#endif // !defined(AFX_DATABASEELEMENT_H__6335ABE4_5316_4254_9325_AA076DF6C4C9__INCLUDED_)
